package cn.ichiva.puppet.example.base.p1;

import javafx.fxml.FXML;
import javafx.fxml.impl.AbstractPuppetComponent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

/**
 * 条件渲染,事件绑定
 */
public class L4IfComponent extends AbstractPuppetComponent {
    @FXML
    boolean flag = true;

    @Override
    public CharSequence render() {
        imports(VBox.class, Label.class, Button.class);
        return """
                <VBox>
                    <Label text="Puppet Master" if="${flag}" />
                    <Button text="显示/隐藏" onAction="#toggle" />
                </VBox>
                """;
    }

    @FXML
    public void toggle(){
        flag = !flag;
        update();
    }
}
